import numpy as np



def set_essential_bc(tspace,sh,PDE):
    #最小二乘得到边界条件
    mesh = tspace.mesh
    index = mesh.ds.boundary_edge_index() #boundary index
    facebd2dof = tspace.face2dof[index] #(NEbd,ldof,tdim)

    
    gdof = tspace.number_of_global_dofs()
    isBdDof = np.zeros(gdof,dtype=np.bool)
    isBdDof[facebd2dof[:,1:]] = True


    pp = mesh.entity_barycenter('edge',index=index)
    z = (PDE.r_0+PDE.d/2)*np.cos(PDE.alpha)-PDE.b
    idx, = np.nonzero(pp[...,1]<(z+1e-10))

    rho = pp[idx,0]

    sh[facebd2dof[idx,:,1]] += PDE.p*rho[:,None]


    return isBdDof








